/**
 * 
 */


(function(){
    var App = TM.App = TM.App || {}
})();


TM.loadScript("graphics", "graphics");

// dom をロード
TM.loadScript("app", "game-element", function(){


(function(){
    
    
    /**
     * @lends   TM.App.Sprite.prototype
     */
    var Sprite = TM.App.Sprite = TM.createClass({
        
        superClass: TM.App.GameElement,
        
        graphics: null,
        
        /**
         * Sprite クラス
         * 描画は定義してあるので draw の実装は不要.
         * @constructs
         * @class       Sprite クラス
         * @extends     TM.App.GameElement
         * @see <a href="./../../test/app/sprite-test.html">Test Program</a>.
         */
        init: function(canvas) {
            TM.App.GameElement.prototype.init.apply(this);
            
            if (canvas instanceof HTMLCanvasElement) {
                this.graphics = TM.Graphics.Graphics(canvas);
            }
            else if (canvas instanceof CanvasRenderingContext2D) {
                this.graphics = TM.Graphics.Graphics(canvas.canvas);
            }
            else if (canvas instanceof TM.Graphics.Graphics) {
                this.graphics = canvas;
            }
            else {
                this.graphics = TM.Graphics.Graphics(TM.$create("canvas"));
                this.width = Sprite.DEFAULT_WIDTH;
                this.height= Sprite.DEFAULT_HEIGHT;
            }
            
            // context の中心に移動しておく
            this.graphics.setTransform(1, 0, 0, 1, this.width/2, this.height/2);
        },
        
        draw: function(graphics) {
            graphics.drawImage(this.graphics.canvas,
                0, 0, this.width, this.height,
                -this.width/2, -this.height/2, this.width, this.height);
            return ;
            ctx.drawImage(this.image.canvas,
                0, 0, this.width, this.height,
                -this.width/2, -this.height/2, this.width, this.height);
        }
        
    });
    
    Sprite.DEFAULT_WIDTH = 100;
    Sprite.DEFAULT_HEIGHT= 100;
    
    Sprite.prototype.accessor("width", {
        "get": function()   { return this.graphics.width; },
        "set": function(v)  { this.graphics.width = v; this.graphics.setTransform(1, 0, 0, 1, this.width/2, this.height/2); }
    });
    
    Sprite.prototype.accessor("height", {
        "get": function()   { return this.graphics.height; },
        "set": function(v)  { this.graphics.height = v; this.graphics.setTransform(1, 0, 0, 1, this.width/2, this.height/2);   }
    });
    
})();


});














